

function say() {
    alert("653. 两数之和 IV - 输入 BST");
}
say();



/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} k
 * @return {boolean}
 */
var findTarget = function(root, k) {
    //10:13-28
    // 转数组

    var arr = []
    dfs(root, arr)

    var left = 0
    var right = arr.length - 1
    while(left < right) {
        var sum = arr[left] + arr[right]
        if(sum == k){
            return true
        }else if(sum < k){
            left++
        }else {
            right--
        }
    }

    return false
};


function dfs(root, arr) {
    if(root) {
        dfs(root.left, arr)
        arr.push(root.val)
        dfs(root.right, arr)
    }
}
